package com.ruoyi.project.system.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.domain.SysCategory;
import com.ruoyi.project.system.service.ISysCategoryService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 分类Controller
 *
 * @author theme
 * @date 2020-06-23
 */
@Api(description = "分类Controller" )
@RestController
@RequestMapping("/system/category" )
public class SysCategoryController extends BaseController {
    @Autowired
    private ISysCategoryService sysCategoryService;

/**
 * 查询分类列表
 */
@ApiOperation("查询分类列表" )
@PreAuthorize("@ss.hasPermi('system:category:list')" )
@GetMapping("/list" )
        public TableDataInfo list(SysCategory sysCategory) {
        startPage();
        sysCategory.setDelFlag("0");
        List<SysCategory> list = sysCategoryService.selectSysCategoryList(sysCategory);
        return getDataTable(list);
    }

    /**
     * 查询分类列表
     */
    @ApiOperation("查询分类列表" )
    @GetMapping("/getList" )
    public AjaxResult getList() {
        SysCategory sysCategory=new SysCategory();
        sysCategory.setDelFlag("0");
        List<SysCategory> list = sysCategoryService.selectSysCategoryList(sysCategory);
        return AjaxResult.success(list);
    }

    
    /**
     * 获取分类详细信息
     */
    @ApiOperation("获取分类详细信息" )
    @PreAuthorize("@ss.hasPermi('system:category:query')" )
    @GetMapping(value = "/{categoryId}" )
    public AjaxResult getInfo(@PathVariable("categoryId" ) Long categoryId) {
        return AjaxResult.success(sysCategoryService.selectSysCategoryById(categoryId));
    }

    /**
     * 新增分类
     */
    @ApiOperation("新增分类" )
    @PreAuthorize("@ss.hasPermi('system:category:add')" )
    @Log(title = "分类" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCategory sysCategory) {
        return toAjax(sysCategoryService.insertSysCategory(sysCategory));
    }

    /**
     * 修改分类
     */
    @ApiOperation("修改分类" )
    @PreAuthorize("@ss.hasPermi('system:category:edit')" )
    @Log(title = "分类" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCategory sysCategory) {
        return toAjax(sysCategoryService.updateSysCategory(sysCategory));
    }

    /**
     * 删除分类
     */
    @ApiOperation("删除分类" )
    @PreAuthorize("@ss.hasPermi('system:category:remove')" )
    @Log(title = "分类" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{categoryIds}" )
    public AjaxResult remove(@PathVariable Long[] categoryIds) {
        return toAjax(sysCategoryService.deleteSysCategoryByIds(categoryIds));
    }
}
